# -*- coding: utf-8 -*-


class CacheAction(object):
    def __init__(self, cache):
        self.cache = cache

    def token(self):
        return TokenCache(self.cache)

    def risk_email(self):
        return RiskEmailCache(self.cache)

    def rptsys(self):
        return SystemhealthCache(self.cache)

    def ruaptcha(self):
        return RuaptchaCache(self.cache)

    def verify_email(self):
        return VerifyEmailCache(self.cache)

    def reset_password(self):
        return ResetPasswordCache(self.cache)


class TokenCache(object):
    def __init__(self, cache):
        self.cache = cache
        self.head_name = 'token_'

    def set(self, userid, value):
        return self.cache.set(self.head_name + str(userid), value)

    def get(self, userid):
        return self.cache.get(self.head_name + str(userid))


class VerifyEmailCache(object):
    def __init__(self, cache):
        self.cache = cache
        self.head_name = 'verify_email_'

    def set(self, code, userid, expires=24 * 60 * 60):
        return self.cache.set(self.head_name + code, userid, expires)

    def get(self, code):
        return self.cache.get(self.head_name + code)

    def delete(self, code):
        return self.cache.delete(self.head_name + code)


class ResetPasswordCache(object):
    def __init__(self, cache):
        self.cache = cache
        self.head_name = 'reset_password_'

    def set(self, code, userid, expires=24 * 60 * 60):
        return self.cache.set(self.head_name + code, userid, expires)

    def get(self, code):
        return self.cache.get(self.head_name + code)

    def delete(self, code):
        return self.cache.delete(self.head_name + code)


class RuaptchaCache(object):
    def __init__(self, cache):
        self.cache = cache
        self.head_name = 'ruaptcha_'

    def set(self, t, code, expires=600):
        return self.cache.set(self.head_name + t, code, expires)

    def get(self, t):
        return self.cache.get(self.head_name + t)


class RiskEmailCache(object):
    def __init__(self, cache):
        self.cache = cache
        self.head_name = 'risk_email_'

    def set(self, email, value, expires=24 * 60 * 60):
        return self.cache.set(self.head_name + str(email), value,
                              expires)

    def get(self, email):
        return self.cache.get(self.head_name + str(email))


class SystemhealthCache(object):
    def __init__(self, cache):
        self.cache = cache
        self.head_name = 'systemhealth_'

    def set(self, sn, value, expires=60):
        return self.cache.set(self.head_name + str(sn), value, expires)

    def get(self, sn):
        return self.cache.get(self.head_name + str(sn))
